package libs

import (
	"github.com/mojocn/base64Captcha"
)

//创建验证码
func CodeCaptchaCreate(config string) (string, string) {
	switch config {
	case "Digit":
		//数字验证码配置
		var configD = base64Captcha.ConfigDigit{
			Height:     40,
			Width:      100,
			MaxSkew:    0,
			DotCount:   40,
			CaptchaLen: 4,
		}
		//创建数字验证码.
		//GenerateCaptcha 第一个参数为空字符串,包会自动在服务器一个随机种子给你产生随机uiid.
		idKeyD, capD := base64Captcha.GenerateCaptcha("", configD)
		base64stringD := base64Captcha.CaptchaWriteToBase64Encoding(capD)
		return idKeyD, base64stringD
	case "Audio":
		//声音验证码配置
		var configA = base64Captcha.ConfigAudio{
			CaptchaLen: 6,
			Language:   "zh",
		}
		//创建声音验证码
		//GenerateCaptcha 第一个参数为空字符串,包会自动在服务器一个随机种子给你产生随机uiid.
		idKeyA, capA := base64Captcha.GenerateCaptcha("", configA)
		//以base64编码
		base64stringA := base64Captcha.CaptchaWriteToBase64Encoding(capA)
		return idKeyA, base64stringA
	case "Character":
		//字符,公式,验证码配置
		var configC = base64Captcha.ConfigCharacter{
			Height: 60,
			Width:  240,
			//const CaptchaModeNumber:数字,CaptchaModeAlphabet:字母,CaptchaModeArithmetic:算术,CaptchaModeNumberAlphabet:数字字母混合.
			Mode:               base64Captcha.CaptchaModeNumber,
			ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
			ComplexOfNoiseDot:  base64Captcha.CaptchaComplexLower,
			IsShowHollowLine:   false,
			IsShowNoiseDot:     false,
			IsShowNoiseText:    false,
			IsShowSlimeLine:    false,
			IsShowSineLine:     false,
			CaptchaLen:         6,
		}
		//创建字符公式验证码.
		//GenerateCaptcha 第一个参数为空字符串,包会自动在服务器一个随机种子给你产生随机uiid.
		idKeyC, capC := base64Captcha.GenerateCaptcha("", configC)
		//以base64编码
		base64stringC := base64Captcha.CaptchaWriteToBase64Encoding(capC)
		return idKeyC, base64stringC
	default:
		return "", ""
	}
}

func VerifyCaptcha(captchaId, val string) bool {
	return base64Captcha.VerifyCaptcha(captchaId, val)
}
